package by.amakarevich.services.impl;

import javax.inject.Inject;

import org.apache.commons.lang3.Validate;
import org.springframework.stereotype.Service;

import by.amakarevich.dataaccess.HookDao;
import by.amakarevich.dataaccess.ProductDao;
import by.amakarevich.datamodel.Hook;
import by.amakarevich.datamodel.Product;
import by.amakarevich.services.HookService;

@Service
public class HookServiceImpl implements HookService {
	@Inject
	private HookDao hookDao;
	
	@Inject
	private ProductDao productDao;
	
	@Override
	public void createNewHook(Hook hook,  Product product) {
		Validate.isTrue(hook.getId() == null, "This method should be called for 'not saved yet' profile only. Use UPDATE instead");
		hook.setProduct(product);
		hookDao.insert(hook);
	}

	@Override
	public Hook get(Long id) {
		return hookDao.getById(id);
	}

	@Override
	public void updateHook(Hook hook) {
		hookDao.update(hook);
	}

	@Override
	public void removeHook(Long id) {

		hookDao.delete(id);
		productDao.delete(id);

	}
	  @Override
	    public void deleteAll() {
		  hookDao.deleteAll();
		  productDao.deleteAll();
	    }
}
